import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MainInterface extends JFrame {
    public MainInterface() {
        setTitle("二手交易平台 - 主界面");
        setSize(400, 700);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        
        // 主面板
        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new BorderLayout());
        
        // 顶部用户信息
        JPanel userPanel = new JPanel(new BorderLayout());
        userPanel.add(new JLabel("# 用户********  ID:********"), BorderLayout.WEST);
        mainPanel.add(userPanel, BorderLayout.NORTH);
        
        // 功能按钮区
        JPanel functionPanel = new JPanel(new GridLayout(2, 4, 10, 10));
        functionPanel.add(new JButton("红包(1)"));
        functionPanel.add(new JButton("收藏(0)"));
        functionPanel.add(new JButton("足迹(3)"));
        JButton cartButton = new JButton("购物车(0)");
        functionPanel.add(cartButton);
        functionPanel.add(new JButton("购买"));
        functionPanel.add(new JButton("出售"));
        functionPanel.add(new JButton("代发货"));
        functionPanel.add(new JButton("待收货"));
        functionPanel.add(new JButton("售后"));
        JButton mySalesButton = new JButton("我卖的");
        functionPanel.add(mySalesButton);
        functionPanel.add(new JButton("我发布"));
        
        // 资产评估区
        JPanel assetPanel = new JPanel(new BorderLayout());
        assetPanel.add(new JLabel("我的资产    测一测，手机能买到多少钱？"), BorderLayout.NORTH);
        assetPanel.add(new JLabel("¥1855 预估可得    测一测"), BorderLayout.CENTER);
        assetPanel.add(new JLabel("vivo IQOO 11 Pro | 限时补贴券 ¥214"), BorderLayout.SOUTH);
        
        // 钱包功能区
        JPanel walletPanel = new JPanel(new GridLayout(1, 4, 10, 10));
        walletPanel.add(new JButton("我的钱包"));
        walletPanel.add(new JButton("余额"));
        walletPanel.add(new JButton("银行卡"));
        walletPanel.add(new JButton("更多"));
        
        // 底部功能区
        JPanel bottomPanel = new JPanel(new GridLayout(1, 5, 10, 10));
        bottomPanel.add(new JButton("上门回收"));
        bottomPanel.add(new JButton("招商"));
        bottomPanel.add(new JButton("租享生活"));
        bottomPanel.add(new JButton("客服中心"));
        bottomPanel.add(new JButton("安全中心"));
        
        // 导航栏
        JPanel navPanel = new JPanel(new GridLayout(1, 6, 10, 10));
        navPanel.add(new JButton("官方集"));
        navPanel.add(new JButton("集市"));
        navPanel.add(new JButton("发布"));
        navPanel.add(new JButton("ERYIGI"));
        navPanel.add(new JButton("收藏"));
        navPanel.add(new JButton("我的"));
        
        // 组装主界面
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
        contentPanel.add(functionPanel);
        contentPanel.add(assetPanel);
        contentPanel.add(walletPanel);
        contentPanel.add(bottomPanel);
        contentPanel.add(navPanel);
        
        mainPanel.add(contentPanel, BorderLayout.CENTER);
        add(mainPanel);
        
        // 添加按钮事件
        cartButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ShoppingCartInterface().setVisible(true);
                dispose();
            }
        });
        
        mySalesButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new MySalesInterface().setVisible(true);
                dispose();
            }
        });
    }
    
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MainInterface().setVisible(true);
            }
        });
    }
}